/**
 * Copyright (C), 2020-2020, 软件公司
 * FileName: Trigger.java
 * Author:   cakin
 * Date:     2020/4/23
 * Description: receiveTask流程执行
 */
package com.syc.activiti.chapter9;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.Execution;
import org.activiti.engine.runtime.ProcessInstance;

/**
 * @className: Trigger
 * @description: receiveTask流程执行
 * @date: 2020/4/23
 * @author: cakin
 */
public class Trigger {

    public static void main( String[] args ) {
        // 创建流程引擎
        ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
        // 得到流程存储服务实例
        RepositoryService repositoryService = engine.getRepositoryService();
        // 得到运行时服务组件
        RuntimeService runtimeService = engine.getRuntimeService();
        // 部署流程描述文件
        repositoryService.createDeployment()
                .addClasspathResource("bpmn/chapter9/trigger.bpmn").deploy();
        // 开始流程
        ProcessInstance pi = runtimeService
                .startProcessInstanceByKey("vacationRequest");
        // 查找执行流（当前只有一个执行流）
        Execution exe = runtimeService.createExecutionQuery().activityId("receivetask1").singleResult();
        if (exe != null) {
            System.out.println("当前流程节点为： receivetask1 " + exe.getId());
        }
        // 触发等待节点
        runtimeService.trigger(exe.getId());
        // 查询当前的流程节点
        exe = runtimeService.createExecutionQuery().activityId("usertask1").singleResult();
        if (exe != null) {
            System.out.println("当前流程节点为： usertask1 "+ exe.getId());
        }
    }
}
